package com.xbaoziplus.simple_spring.beans.factory.support;

import com.xbaoziplus.simple_spring.beans.factory.config.SingletonBeanRegistry;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author xbaozi
 * @version 1.0
 * @classname DefaultSingletonBeanRegistry
 * @date 2023-04-18  16:20
 * @description 默认单例对象注册接口实现
 */
public class DefaultSingletonBeanRegistry implements SingletonBeanRegistry {

    /** 存放 bean 实例(单例) */
    private Map<String, Object> singletonObjects = new ConcurrentHashMap<>();


    @Override
    public Object getSingleton(String beanName) {
        return singletonObjects.get(beanName);
    }

    @Override
    public void registerSingleton(String beanName, Object singletonObject) {
        singletonObjects.put(beanName, singletonObject);
    }
}
